#ifndef _IOTHREADPOOL_H_
#define _IOTHREADPOOL_H_

#include <compat/queue.h>
#include <compat/qqueue.h>
#include <compat/thread.h>

#include "ioeventdef.h"
#include "iothread.h"

uvNameSpaceBegin

#define TP_ERROR -1
#define TP_SUC 0

struct WokerCb {
	io_data		io;
	_QUEUE		node;
};

struct io_thread_pool {
	async_fun_cb startfunction;
	async_fun_cb stopfunction;
	async_fun_cb workerproc;
	void* pdata;
	unsigned long threadcount;
	io_thread_t* threads;

	os_sem_t	threadpool_sem;
	os_sem_t	thread_sem;
	os_sem_t	thread_io_sem;
	os_sem_t	thread_exit_sem;
	os_mutex_t	mutex;



	/*
	unsigned long iothreadcount;
	io_thread_t* iothreads;


	_QUEUE wq;
	_QUEUE exit_message;

	os_cond_t cond;
	*/
	unsigned long index;

};

int	init_threadpool(io_thread_pool*	pThreadPool, unsigned long threads,void* pData);
int	run_threadpool(io_thread_pool* pThreadPool, async_fun_cb Startfn, async_fun_cb Stopfn);
int	stop_threadpool(io_thread_pool* pThreadPool);
int	notify_threadpool();

io_thread_t* geteventloop();
io_thread_pool* getthreadpool();

uvNameSpaceEnd

#endif

